<?php

namespace app\admin\service;

use app\model\Album;
use app\model\AlbumGroup;

/**
 * Class AlbumService
 * @package app\service
 */
class AlbumService extends CommonService
{
    /**
     * @desc 获取图片分页数据
     * @param $aid
     * @param $gid
     */
    public static function getPageList($aid, $gid)
    {
        $where['aid'] = $aid;
        if (!empty($gid))
        {
            $where['groupid'] = $gid;
        }
        return Album::getPageList($where, '', 'id DESC', null, 6);
    }

    /**
     * @desc 获取分组数据
     * @param $aid
     * @return array
     */
    public static function getGroupList($aid)
    {
        return AlbumGroup::getList(['aid' => $aid]);
    }

    /**
     * @desc 获取图片总数
     * @param $aid
     * @param $gid
     * @return int
     */
    public static function getAlbumCount($aid, $gid)
    {
        return Album::getCount(['aid' => $aid, 'groupid' => $gid]);
    }

    /**
     * @desc 新增分组
     * @param $name
     * @return mixed
     */
    public static function addGroup($name)
    {
        $data['name'] = $name;
        return AlbumGroup::addOne($data);
    }

    /**
     * @desc 编辑分组
     * @param $gid
     * @param $name
     * @return \app\BaseModel|mixed
     */
    public static function editGroup($gid, $name)
    {
        $data['name'] = $name;
        $where['id'] = $gid;
        return AlbumGroup::updateOne($data, $where);
    }

    /**
     * @desc 删除分组
     * @param $ids
     * @return bool
     */
    public static function delGroup($ids)
    {
        return AlbumGroup::deleteByIds($ids);
    }

    /**
     * @desc 添加图片
     * @param $data
     * @return mixed
     */
    public static function addOne($data)
    {
        return Album::addOne($data);
    }

    public static function updateAlbum($ids, $data)
    {
        return Album::updateByIds($ids, $data);
    }

    /**
     * @desc 删除图片
     * @param $ids
     * @return bool
     */
    public static function delAlbum($ids)
    {
        return Album::deleteByIds($ids);
    }
}